<?php
include '../dbconnect.php';

?>
<!DOCTYPE html>
<html lang="zh">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <!-- <meta name="description" content=""> -->
    <!-- <meta name="author" content=""> -->
    <!-- <link rel="icon" href="../../favicon.ico"> -->

    <title>goodsList</title>

    <!-- Bootstrap core CSS -->
    <link href="./css/bootstrap.min.css" rel="stylesheet">

    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <!-- <link href="../../assets/css/ie10-viewport-bug-workaround.css" rel="stylesheet"> -->

    <!-- Custom styles for this template -->
    <link href="./css/navbar-fixed-top.css" rel="stylesheet">

    <!-- Just for debugging purposes. Don t actually copy these 2 lines! -->
    <!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
    <!-- <script src="../../assets/js/ie-emulation-modes-warning.js"></script> -->

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->

    <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->

    <script src="js/jquery.js"></script>
      <script src="js/jquery-3.4.1.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <!-- <script src="../../assets/js/ie10-viewport-bug-workaround.js"></script> -->
	<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
  </head>

  <body>

    <!-- Fixed navbar -->
    <?php include 'adminHeader.php'; ?>

    <div class="container">

      <!-- Main component for a primary marketing message or call to action -->
      <div class="jumbotron">
        <h1>Appointment Management</h1>
        <p>This is Reviews management, where you can perform Create, Read, Update, Delete operations on reviews</p>
      </div>

                <table class="table table-striped">

        <thead>
          <tr>
            <th>id</th>
            <th>username</th>
            <th>email</th>
            <th>phone</th>
            <th>type</th>
            <th>desc</th>
			<th>time</th>
			<th>creator</th>
          </tr>
        </thead>
        <tbody>
      <?php
      $sql = "SELECT * FROM appointment where IS_DELETE = 0";
      $result = $conn->query($sql);
      if ($result->num_rows > 0) {
        // 输出每行数据
        while($row = $result->fetch_assoc()) {
          ?>
		<tr>
		  <td><?php echo $row["APPOINTMENT_ID"]; ?></td>
		  <td><?php echo $row["APPOINTMENT_USER_NAME"]; ?></td>
		  <td><?php echo $row['APPOINTMENT_USER_EMAIL'] ?></td>
		  <td><?php echo $row['APPOINTMENT_USER_PHONE'] ?></td>
		  <td><?php echo $row['APPOINTMENT_SERVICE_TYPE'] ?></td>
		  <td><?php echo $row['APPOINTMENT_SERVICE_DESC'] ?></td>
		  <td><?php echo $row['APPOINTMENT_SERVICE_TIME'] ?></td>
		  <td>
			<button class="btn btn-danger" onclick="deleteReview('<?php echo $row['APPOINTMENT_ID']; ?>')">Delete</button>
			</div>

		  </td>
		</tr>
          <?php
        }
      } else {
        echo "0 result";
      }
      $conn->close();
      ?>
    </tbody>
  </table>


    </div> <!-- /container -->



<script type="text/javascript">
	function deleteReview(gid) {
		if (confirm('Are you sure you want to delete this review?')) {
			$.post("delappointments.php", {
				APPOINTMENT_ID: gid
			}, function(data, status) {
				try {
					var response = JSON.parse(data);
					if (response.status === 'success') {
						alert('Review deleted successfully!');
						setTimeout(function() {
							location.href = "reviewsList.php";
						}, 300);
					} else {
						alert('Failed to delete review: ' + response.message);
					}
				} catch (e) {
					console.error('Error parsing JSON response:', e);
					alert('An error occurred while processing the response.');
				}
			}).fail(function(jqXHR, textStatus, errorThrown) {
				console.error('AJAX request failed:', textStatus, errorThrown);
				alert('An error occurred while deleting the review.');
			});
		}
	}
</script>
  </body>
</html>
